package io.geekidea.boot.system.enums;

import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * 系统菜单类型
 *
 * @author geekidea
 * @date 2024/1/21
 **/
@Getter
public enum SysMenuType {
    ROOT(0, "根目录"),
    DIR(1, "目录"),
    MENU(2, "菜单"),
    FUN_PERMISSION(3, "功能权限");

    private final Integer code;
    private final String desc;

    SysMenuType(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    private static final Map<Integer, SysMenuType> map = new HashMap<>();

    static {
        for (SysMenuType type : values()) {
            map.put(type.code, type);
        }
    }

    public static Integer getCode(SysMenuType type) {
        if (type == null) {
            return null;
        }
        return type.code;
    }

    public static SysMenuType get(Integer code) {
        return map.get(code);
    }

    public static String getDesc(Integer code) {
        SysMenuType type = get(code);
        if (type == null) {
            return null;
        }
        return type.getDesc();
    }

}
